﻿using System;
using System.Windows;
using BitMiracle.LibTiff.Classic;

namespace FirstFloor.Documents.IO.LibTiff
{
    /// <summary>
    /// Provide extension methods for the <see cref="BitMiracle.LibTiff.Classic.Tiff"/> class.
    /// </summary>
    internal static class TiffExtensions
    {
        /// <summary>
        /// Gets the size of the current frame in pixels.
        /// </summary>
        /// <returns></returns>
        public static Size GetFrameSize(this Tiff image)
        {
            if (image == null) {
                throw new ArgumentNullException("image");
            }

            var frameWidthField = image.GetField(TiffTag.IMAGEWIDTH);
            var frameHeightField = image.GetField(TiffTag.IMAGELENGTH);

            var frameWidth = frameWidthField != null && frameWidthField.Length > 0 ? frameWidthField[0].ToInt() : 0;
            var frameHeight = frameHeightField != null && frameHeightField.Length > 0 ? frameHeightField[0].ToInt() : 0;

            return new Size(frameWidth, frameHeight);
        }
    }
}
